package KAs;

import java.util.Random;
import java.util.Scanner;

public class HuoChaiGame {
    static int last,user,computer;
    static Scanner input=new Scanner(System.in);
    static void quhuochai(){
        Random r= new Random();
        while (true){
            System.out.printf("--- 目前还有火柴%d根 ---\n", last);
            System.out.printf("用户取火柴数量：");
            user=input.nextInt();
            if (user<1||user>=4||user>last){
                System.out.printf("取出火柴数量有问题，应为1~3根");
                continue;
            }
            last=last-user;
            System.out.printf("用户取出%d根火柴\n",user);
            if (last==0){
                System.out.printf("Winner is You!!!");
                break;

            }else{
                if (last>3){
                    computer=r.nextInt(3)+1;
                }else if (last<=1){
                    computer=1;
                }else {
                    computer=last-1;
                }
                last=last-computer;
                System.out.printf("电脑取出%d根火柴\n",computer);
                if (last==0){
                    System.out.printf("Winner is Computer!!!");
                    break;
                }
            }

        }
    }
    public static void main(String[] args){
        last=(int)(Math.random()*(50-20+1)+20);
        System.out.printf("火柴数量："+last);
        quhuochai();
    }

}